﻿using System;
using System.Diagnostics;

namespace Gwn.Library.MvpVm.Extensions
{
    /// <summary>
    /// 
    /// </summary>
    public static class ProcessTypeExtension
    {
        /// <summary>
        /// Gets the type of the process.
        /// </summary>
        /// <param name="enumValue">The enum value.</param>
        /// <returns></returns>
        public static T GetProcessType<T>(this Enum enumValue)
        {
            try
            {
                var processType = (T)Enum.Parse(typeof(T), enumValue.ToString(), true);
                return processType;
            }
            catch
            {
                Debug.WriteLine("Non-critical exception: GetProcessType [{0}] did not contain {1}", typeof(T), enumValue);

                // Every enum that is used in the ProcessTypeEvent must have a
                // NotApplicable item
                var processType = (T)Enum.Parse(typeof(T),"NotApplicable", true);
                return processType;
            }
           
        }

    }
}
